//
//  PlayNDropViewController.m
//  CCMPlayNDropViewSample
//
//  Created by Compean on 29/11/14.
//  Copyright (c) 2014 Carlos Compean. All rights reserved.
//

#import "PlayNDropViewController.h"
#import <MaryPopin/UIViewController+MaryPopin.h>
#import "CCMPlayNDropView.h"
#import "HSDatePickerViewController.h"
//#import "MGConferenceDatePickerDelegate.h"
#import "DatePickerViewController.h"
@interface PlayNDropViewController () <HSDatePickerViewControllerDelegate>
@property (strong, nonatomic)CCMPlayNDropView *dropView;
//@property (strong, nonatomic)MGConferenceDatePicker *datePicker;
@property (nonatomic, strong) NSDate *selectedDate;
@end

@implementation PlayNDropViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.dropView = [[CCMPlayNDropView alloc] initWithFrame:CGRectMake(0, 0, 300, 400)];
    
    [self.dropView.saveBtn addTarget:self action:@selector(saveDownTheTip:) forControlEvents:UIControlEventTouchUpInside];
    [self.dropView.notificationView.chooseDate addTarget:self action:@selector(createChooseDatePicker:) forControlEvents:UIControlEventTouchUpInside];
    
    self.dropView.backgroundColor = [UIColor whiteColor];
    self.dropView.delegate = self;
    [self.view addSubview:self.dropView];
}

// 存储便条内容
- (void)saveDownTheTip:(id)sender
{
    
}

// 创建时间选择器
- (void)createChooseDatePicker:(UIButton *)btn
{
    HSDatePickerViewController *hsdpvc = [HSDatePickerViewController new];
    hsdpvc.delegate = self;
    if (self.selectedDate) {
        hsdpvc.date = self.selectedDate;
    }
    [self presentViewController:hsdpvc animated:YES completion:nil];
    
}

#pragma mark - HSDatePickerViewControllerDelegate
- (void)hsDatePickerPickedDate:(NSDate *)date {
    NSLog(@"Date picked %@", date);
    NSDateFormatter *dateFormater = [NSDateFormatter new];
    dateFormater.dateFormat = @"yyyy.MM.dd HH:mm:ss";
    self.dropView.notificationView.timeLabel.text = [dateFormater stringFromDate:date];
    self.selectedDate = date;
}

//optional
- (void)hsDatePickerDidDismissWithQuitMethod:(HSDatePickerQuitMethod)method {
    NSLog(@"Picker did dismiss with %lu", (unsigned long)method);
}

//optional
- (void)hsDatePickerWillDismissWithQuitMethod:(HSDatePickerQuitMethod)method {
    NSLog(@"Picker will dismiss with %lu", (unsigned long)method);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)CCMPlayNDropViewWillStartDismissAnimationWithDynamics:(CCMPlayNDropView *)view{
    self.view.superview.userInteractionEnabled = NO;
    self.view.userInteractionEnabled = NO;
}

-(void)CCMPlayNDropViewDidFinishDismissAnimationWithDynamics:(CCMPlayNDropView *)view{
    self.view.superview.userInteractionEnabled = YES;
    CGRect frame = self.view.frame;
    frame.origin.y = -1000;
    self.view.frame = frame;
    [self.parentViewController dismissCurrentPopinControllerAnimated:YES];
}

//-(void)dismissWithoutAnimation{
//    [self dismissCurrentPopinControllerAnimated:NO];
//}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
// 版权属于原作者
// http://code4app.com (cn) http://code4app.net (en)
// 发布代码于最专业的源码分享网站: Code4App.com